<!DOCTYPE html>
<html>
<meta charset="utf-8">
<head th:include="include :: header"></head>
<body class="gray-bg">
<div class="wrapper wrapper-content ">
    <div class="col-sm-12">
        <div class="ibox">
            <div class="ibox-body">
                <div class="fixed-table-toolbar">
                    <div class="columns pull-right">
                        <button class="btn btn-success" onclick="reLoad()">查询</button>
                    </div>
                    <div class="columns pull-right col-md-2 nopadding">
                        <select id="productid" name="productid"
                                class="form-control" type="text">
                            <option value="">---请选择产品---</option>
                        </select>
                    </div>
                    <div class="columns pull-right col-md-2 nopadding">
                        <select id="channelid" onchange="getDistrict()" name="channelid"
                                class="form-control" type="text">
                            <option value="">---请选择渠道---</option>
                        </select>
                    </div>
                    <div class="columns pull-right col-md-2 nopadding">
                        <input id="linkname" type="text" class="form-control"
                               placeholder="链接名称">
                    </div>
                </div>
                <input id="channelstate" value="1" type="hidden">
                <table id="exampleTable" data-mobile-responsive="true">
                </table>
            </div>
        </div>
    </div>
</div>
<!--shiro控制bootstraptable行内按钮看见性 来自bootdo的创新方案 -->
<div>
    <script type="text/javascript">
        var s_edit_h = 'hidden';
        var s_remove_h = 'hidden';
        var s_resetPwd_h = 'hidden';
    </script>
</div>
<div shiro:hasPermission="market:productAdvertisement:edit">
    <script type="text/javascript">
        s_edit_h = '';
    </script>
</div>
<div shiro:hasPermission="market:productAdvertisement:remove">
    <script type="text/javascript">
        var s_remove_h = '';
    </script>
</div>
<div shiro:hasPermission="market:productAdvertisement:resetPwd">
    <script type="text/javascript">
        var s_resetPwd_h = '';
    </script>
</div>
</div>
<div th:include="include :: footer"></div>
<script type="text/javascript" src="/js/appjs/market/productAdvertisement/productChannel.js"></script>
<script type="text/javascript" th:inline="javascript">
    $(function () {
        //获取有效的渠道
        $.ajax({
            type: 'get',
            url: '/market/productAdvertisement/getVaildChannel',
            dataType: 'json',
            success: function (datas) {
                //返回list数据并循环获取
                var select = $("#channelid");
                for (var i = 0; i < datas.length; i++) {
                    select.append("<option value='" + datas[i].channelId + "'>"
                        + datas[i].channelName + "</option>");
                }
            }
        });

    })

    function getDistrict() {
        $("#productid").empty();    //清空二级下拉框，否则会叠加
        var channelid = $("#channelid").val();
        $.ajax({
            type: "post",
            url: '/market/productAdvertisement/getVaildProduct',
            dataType: 'json',
            data: {channelid: channelid},
            success: function (data) {
                var select = $("#productid");
                select.append("<option value=''>"
                    + "---请选择产品---" + "</option>");
                for (var i = 0; i < data.length; i++) {
                    select.append("<option value='" + data[i].productId + "'>"
                        + data[i].productName + "</option>");
                }
            }
        });
    }
</script>


</body>
</html>